package DFdwer;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;

public class DFDFDA {
	public static void main(String[] args) {
		String[] ss={"AB","BC","CD","BD","BE","EF","DE","BD"};
		ArrayList<String> li=new ArrayList<String>();
		aaa(ss,ss[0],li);
		for(String s:li)
		   System.out.println(s);	
	}
	
	public static void aaa(String[] ss,String s,ArrayList<String> li){
	        String st=null;	
			for(int i=0;i<ss.length;i++){
			   st=s;
			   if(s.charAt(s.length()-1)==ss[i].charAt(0)&&ss[i].charAt(0)<ss[i].charAt(1)){
				   st+=ss[i].charAt(1);
				   aaa(ss,st,li);
			   }		   
			}		
			if(s.length()>3){
				if(li.size()==0){
					li.add(s);	
				}else{
				   for(int n=0;n<li.size();n++){
					   if(s.equals(li.get(n)))
					 	   break;
				       else if(n==li.size()-1)
					       li.add(s);
			       }
				}
			}
	}

	public static void main11(String[] args) {
		
		AA1 a=new AA2();
		a.get();
		a.get1();
		AA2 a2=(AA2)new AA1();
		//a2.get();
		//a2.get1();
		//a2.get2();
		AA2 a3=new AA2();
		a3.get();
		a3.get1();
		a3.get2();

	}

}
class AA1{
	String s="a";
	public void get(){
		System.out.println(s);
	}
	public void get1(){
		System.out.println(s);
	}
}
class AA2 extends AA1{
	String s="b";
	public void get1(){
		System.out.println("a"+s);
	}
	public void get2(){
		System.out.println("a"+s);
	}
	
}